const app = getApp()
Page({
  data: {
    swiperList: [{
      id: 0,
      type: 'image',
      url: 'https://img-qn.51miz.com/preview/element/00/01/12/94/E-1129475-A8D30765.jpg!/quality/90/unsharp/true/compress/true/fw/840'
    }, {
      id: 1,
        type: 'image',
        url: 'https://img-qn.51miz.com/preview/element/00/01/12/94/E-1129478-92E883D7.jpg!/quality/90/unsharp/true/compress/true/fw/840',
    }, {
      id: 2,
      type: 'image',
      url: 'https://img-qn.51miz.com/preview/element/00/01/12/94/E-1129481-44B9238E.jpg!/quality/90/unsharp/true/compress/true/fw/840'
    }, {
      id: 3,
      type: 'image',
      url: 'https://img-qn.51miz.com/preview/element/00/01/12/94/E-1129480-C804AB5B.jpg!/quality/90/unsharp/true/compress/true/fw/840'
    }, {
      id: 4,
      type: 'image',
      url: 'https://img-qn.51miz.com/preview/element/00/01/12/94/E-1129487-42F9972F.jpg!/quality/90/unsharp/true/compress/true/fw/840'
    }, {
      id: 5,
      type: 'image',
      url: 'https://img-qn.51miz.com/preview/element/00/01/12/94/E-1129489-035DE163.jpg!/quality/90/unsharp/true/compress/true/fw/840'
    }, {
      id: 6,
      type: 'image',
      url: 'https://img-qn.51miz.com/preview/element/00/01/12/94/E-1129482-9C9D1596.jpg!/quality/90/unsharp/true/compress/true/fw/840'
    }]
  },

  onLoad() {
    this.progress_bar(); // 进度条
    this.userId(); // 用户的openid
  },
  progress_bar(){ // 进度条
    let that = this;
    setTimeout(function() {
      that.setData({
        loading: true
      })
    }, 500)
  },
  goto(){
    if(app.globalData.user.site.length == 0){
      wx.reLaunch({
        url:"../mySite/index?datas=homepage/index"
      })
    }else{
      wx.reLaunch({
        url: '../index/index?name=tack',
      })
    }
  },
  purchaseLeft(){ // 门店自取
    if(app.globalData.user.site.length == 0){
      wx.reLaunch({
        url:"../mySite/index?datas=homepage/index"
      })
    }else{
      wx.reLaunch({
        url:"../index/index?name=maps"
      })
    }
  },
  userId(){ // openid的获取
    // wx.login({
    //   //获取code
    //   success: function (res) {
    //     var code = res.code; //返回code
    //     var appId = 'wx34bd12f981e09ab3';
    //     var secret = '5691d714fc1cebf88986db99a8009f09'
    //     wx.request({
    //       url: 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appId + '&secret=' + secret + '&js_code=' + code + '&grant_type=authorization_code',
    //       data: {},
    //       header: {
    //         'content-type': 'json'
    //       },
    //       success: function (res) {
    //         var openid = res.data.openid //返回openid
    //         app.globalData.openid = openid
    //       }
    //     })
    //   }
    // }) // 避免测试时appid不同而引起的获取失败
    app.globalData.app = "23456790"
    console.log(app.globalData.openid);
  }
})